package com.example.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.example.config.resp.ResponseMessage;
import com.example.config.resp.RtnErrUtil;

@ControllerAdvice
public class ActionAdvicer {

	private Logger log = LoggerFactory.getLogger(this.getClass());

	@ExceptionHandler({ Exception.class })
	@ResponseBody
	@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseMessage handleArithmeticException(Exception e) {
		log.error("Handle Action error ", e);
		return RtnErrUtil.handle(e);
	}

	/*@ModelAttribute
	public void print(HttpServletRequest request) {
		String url = request.getRequestURL().toString();
		String method = request.getMethod();
		String uri = request.getRequestURI();
		String userAgent = request.getHeader("User-Agent");
		String params = gson.toJson(request.getParameterMap());
		String cookie = null;

		Cookie[] cookies = request.getCookies();
		if (cookies != null) {
			for (Cookie c : cookies) {
				if (c.getName().endsWith("Token")) {
					cookie = gson.toJson(c);
					break;
				}
			}
		}

		log.debug("URL: {}, URI: {}, Method: {}, Params: {},Cookie:{}, UserAgent:{}",
				url, uri, method, params, cookie, userAgent);
	}*/

}